package com.itheima.dao;

import com.itheima.pojo.CheckItem;
import com.itheima.pojo.CheckItem1;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckItemDao {
    @Insert("insert into t_checkitem (id,code,name,sex,age,price,type,attention,remark) " +
            " values(#{id},#{code},#{name},#{sex},#{age},#{price},#{type},#{attention},#{remark})")
    public Integer insert(CheckItem checkItem);

    //code  name
    @Select("select distinct *  from t_checkitem where code like CONCAT('%',#{QueryString},'%') or name like CONCAT('%',#{QueryString},'%')")
    public List<CheckItem> findAllQueryString(String QueryString);

    @Select("select *  from t_checkitem")
    public List<CheckItem> findAll();
    @Select("select distinct *  from t_checkitem where id=#{id}")
    public CheckItem findById(Integer id);

    @Update("update t_checkitem set code=#{code},name=#{name},sex=#{sex},age=#{age},price=#{price},type=#{type},attention=#{attention},remark=#{remark} where id=#{id}")
    public Integer update(CheckItem checkItem);

    @Delete("delete from t_checkitem where id=#{id}")
    public Integer delete(Integer id);



    @Select("select id,code,name,sex,age,price,type,remark,attention,case when id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{checkGroupId}) then 1 else 0 end as flag from t_checkitem ORDER BY flag DESC")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "code",property = "code"),
            @Result(column = "name",property = "name"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "age",property = "age"),
            @Result(column = "price",property = "price"),
            @Result(column = "type",property = "type"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "attention",property = "attention")
    })
    public List<CheckItem> findAllCheckItemAndCheckGroup1(Integer checkGroupId);

    @Select("select COUNT(*) from t_checkgroup_checkitem where checkitem_id = #{checkItemId};")
    public Integer countCheckgroupId(Integer checkItemId);

    @Select("select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{checkGroupId})")
    public List<CheckItem> findByCheckGroupId(Integer checkGroupId);

}
